#include "buffermoveview.h"
#include "ui_buffermoveview.h"

BufferMoveView::BufferMoveView(int styleIdIn, QWidget *parent) :
    QWidget(parent),
    ui(new Ui::BufferMoveView)
{
    ui->setupUi(this);
    bufferIns=new BufferMoveInstruction;
    setGeometry(5,50,451,544);

}

BufferMoveView::~BufferMoveView()
{
    delete ui;
}

void BufferMoveView::getInput(BufferMoveInstruction &instructionParaOut)
{
    instructionParaOut.noteStr=ui->note_lineEdit->text();
    instructionParaOut.type=(E_BUFFER_MOVE_TYPE)ui->comboBox->currentIndex();
    instructionParaOut.oriPointIndex_1=ui->lineEdit_ori1->text().toInt();
    instructionParaOut.oriPointIndex_2=ui->lineEdit_ori2->text().toInt();
    instructionParaOut.oriPointIndex_3=ui->lineEdit_ori3->text().toInt();

    instructionParaOut.velocity=ui->lineEdit_velocity->text().toDouble();

}

void BufferMoveView::updateView()
{

    ui->lineEdit_velocity->setText(QString::number(bufferIns->velocity));
    ui->note_lineEdit->setText(bufferIns->noteStr);

    ui->comboBox->setCurrentIndex(bufferIns->type);
    ui->lineEdit_ori1->setText(QString::number(bufferIns->oriPointIndex_1));
    ui->lineEdit_ori2->setText(QString::number(bufferIns->oriPointIndex_2));
    ui->lineEdit_ori3->setText(QString::number(bufferIns->oriPointIndex_3));
}

void BufferMoveView::on_save_Btn_clicked()
{
    getInput(*bufferIns);
    finishEditInstruction(*bufferIns,instructionStr);
//    emit finishEditInstructionSignal();
    emit saveInstructionSignal(instructionStr);
}

void BufferMoveView::on_clearNote_Btn_clicked()
{
    ui->note_lineEdit->setText("");
}

void BufferMoveView::finishEditInstruction(BufferMoveInstruction instructionParaIn, QString &instructionStrOut)
{
    instructionStrOut.clear();
    instructionStrOut="BUFFERMOVE ";

    instructionStrOut+=QString::number(instructionParaIn.velocity)+"mm/sec";
    if(E_BUFFER_MOVE_CONST==instructionParaIn.type)
    {
        instructionStrOut+=" CONST";
    }
    else
    {
        instructionStrOut+=" ORI P["+ QString::number(instructionParaIn.oriPointIndex_1)+"]";
        instructionStrOut+=" P["+ QString::number(instructionParaIn.oriPointIndex_2)+"]";
        instructionStrOut+=" P["+ QString::number(instructionParaIn.oriPointIndex_3)+"]";
    }

    instructionStrOut+=";//"+instructionParaIn.noteStr;
}
